package com.zhanggm.starter.uploader;

import com.zhanggm.starter.uploader.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(FileService.class)
@EnableConfigurationProperties(FileProperties.class) //指定属性配置类
public class FileAutoConfiguration {

    @Autowired
    private FileProperties fileProperties;

    /**
     * FileService注入到IOC容器
     * @return
     */
    @Bean //xml<bean class="com.zhanggm.starter.uploader.FileProperties">
    //application.properties文件中：file.enable=true,才实例化FileService
    @ConditionalOnProperty(prefix = "file",value = "enable",havingValue = "true")
    public FileService fileService(){
        return new FileService(fileProperties);
    }
}
